package org.bing.engine.health.gather;

import java.io.BufferedReader;
import java.io.IOException;

import org.bing.engine.health.gather.StreamActor.Action;

public class LoadInfoGather extends AbstractGather {
	private static final String location = "/proc/loadavg";

	@Override
	public Object gather() {
		Object result = actor.doAction(location, new Action() {
			public Object run(BufferedReader reader) throws IOException {
				String line = reader.readLine().trim();
				int first = line.indexOf(" ");
				String lst1mload = line.substring(0, first);
				return Float.parseFloat(lst1mload);
			}

		});
		return result == null ? -1.0 : result;
	}

	public static void main(String[] args) throws Exception {
		LoadInfoGather lg = new LoadInfoGather();
		for (int i = 0; i < 10 * 1; i++) {
			System.out.println(lg.gather());
		}
	}
}
